I wrote this LAP while on my quest to port the Traceroute program to the Macintosh. I 'grew up' on UNIX machines back in the mid-80's, and when I moved over to doing TCP/IP programming on the Mac, I really missed Traceroute... so here's the first part of it.
What does it do?:
What does this LAP do? Well, it is (I hope) an exact duplicate of Apple's default Ethernet LAP with a few notable exceptions. First, this LAP implementes loopback properly. (Although it still doesn't do 127.0.0.1, but that can be added if enough people complain.) Second, this LAP installs a Gestalt selector that allows application programs to perform Raw IP writes and filter all incoming IP packets.
Any known bugs?:
1) Some problems with Powerbooks waking up from sleep mode.
2) Not recognizing some non-Apple Ethernet cards.
3) Not recognizing SCSI based Ethernet devices.
The Gestalt selector:
The Gestalt selector (JMBe), returns a pointer to the following structure (defined in RawIP.h):
typedef struct {
short version; // Version of interface
short availFlags; // What is available
RawWriteProcPtr RawIPWrite; // Raw IP Write routine address
RawIPFilterProcPtr RawIPFilter; // Raw IP Filter routine address
short useFilter; // Non-zero if filter routine is to be called
Ptr user1; // Passed to Filter routine
Ptr user2; // Passed to Filter routine
ProcPtr reserved1;
long reserved2[10];
} RawIPGestaltStruct;
version is the current version of the LAP, in this case 1.
availFlags lists what features are available in the LAP. The two currently defined flags are kHaveRIPFilter and kHaveRIPWrite. I did this so I can distribute a version of the LAP source code that does not have IP filtering in it (more on this later).
RawIPWrite is the address of the routine to call inside the LAP to perform a raw IP write.
RawIPFilter is a location for you to stick the address of your RawIP filter routine.
useFilter tells the LAP whether or not it should call the RawIP filter routine.
user1 and user2 are two fields that are passed to the RawIP filter routine you install, use them as you see fit.
How to send Raw IP packets:
To send a RawIP packet onto the network, allocate a RawWriteParam structure. Stick your A5 value in the userA5 field. Fill out the wdsEntry to point to your IP packet in memory. (Be sure to set the length field!). Finally, you can place the address of a completion routine in the iop.ioCompletion field. Then just call the RawWriteIP function, using the calling conventions typedef'd in RawWriteProcPtr. It's that easy. The RawIPWrite function will return an error directly, or in the iop.ioResult field of the RawWriteParam structure.
Those of you who are familliar with the low level routines in MacTCP may recognize the RawWriteParam structure as something else in disguise. Don't let your knowledge fool you! DO NOT try to use any of the reserved fields in the RawWriteParam structure, it won't neccessarily do what you would expect.
How to filter incoming IP packets:
Create a filter function in your application. The filter function should be of the form typedef'd as RawIPFilterProcPtr. The filter function should return true if the LAP should pass the IP packet onto MacTCP, otherwise the packet will be discarded and MacTCP will never see it. The IPdata field points to the incoming IP packet, and the length field gives you its length. You may modify the packet data if you wish. However, changing the length of the packet will not work. The filter function will only be called if the useFilter field in the Gestalt structure is non-zero. Install your filter _before_ setting the userFilter field to a non-zero value. Setting the useFilter field to zero will disable packet filtering. I reccomend your application patch ExitToShell to zero the useFilter field, just in case.
So where's Traceroute?:
MacTraceroute should have come with this LAP and Release Notes file. If not, you can get it from ftp.jbrowne.com in the Projects directory, or from your local INFO-MAC mirror.
What about source code?:
I can give out the source code to 90% of the LAP. The code in there that lets me do IP packet filtering, however, is private. Check ftp.jbrowne.com for the archive. If it isn't there, drop me a line at traceroute@jbrowne.com.
Who wrote this?:
The Traceroute Ethernet LAP was written by Jim Browne (jbrowne@jbrowne.com). Jim is a graduate of the University of Illinois - Chambana. Jim currently works for himself at a Sunnyvale, California based networking concern. Jim likes all things related to Led Zeppelin and frisbee (which is a brand name and registered trademark of the wham-o mfg. company). Jim doesn't mind getting bug reports and wish list suggestions via email, so long as they contain "Traceroute" in their subject so Eudora can filter them to the proper mailbox. Beginning with the writing of this file, Jim apparently likes referring to himself in
the third person.
What else has Jim Browne written?:
DNSLib: A library that makes working with MacTCP's DNR much easier by providing application-time callbacks for DNR responses, queueing of DNR requests, and handling of N concurrent DNR questions. MacTraceroute and MacFSP use this library. Note: This has nothing to do with ASLM, SOM, etc.
MacFSP: A Macintosh client for the FSP protocol.
TuboUDP: A library that makes writing UDP code under MacTCP much easier.
During my short stint at Sonic Systems, Inc., I wrote the SonicPPP client, co-designed the interface for the manager of Sonic's QuickStream with Chris Russo (5 diamonds, MacWeek 1/29/96), wrote most of Sonic's Macintosh based PPP server, and helped debug the QuickStream.
In a former life, I worked on two little known programs: NCSA Telnet and NCSA Mosaic… you probably haven't heard of either of them.
Small print:
There is no warranty on this software whatsoever. It has worked without problems for me for quite some time. However, if it crashes your machine or causes you to lose data, I cannot be held responsible. I am trying to make it flawless, but I can't state that it is 100% reliable.
Conclusion:
I've had the TR Ethernet LAP (1.0) running on many different Macintoshes for more than a year. I've had no problems with it. This does not, of course, guarantee that it is bug free. Please report any bugs you find to traceroute@jbrowne.com. I'm very open to suggestions. I decided at the beginning to make this interface open so other people could use it. I figure if people have to run a separate LAP to get this functionality, they don't want to have to swtich between N different LAPs for N different packet filtering applications.
If you would like to modify your SLIP or PPP lap to support this interface, please let me know and I will give you any help I possibly can. I'd like my traceroute program to work over SLIP and PPP.
Enjoy the LAP, and WRITE FREE SOFTWARE for it. ;)
Jim Browne
jbrowne@jbrowne.com
PS: You see, Klaus, I really do release my code... eventually!
Version History:
1.2 March 10, 1996:
Fixed the LAP to be classless with respect to determining broadcast addresses. Should fix the problem experienced by people on subnetted Class C nets (i.e. subnets 255.255.255.x where x is 192, 224, 240, 248, or 252).
1.1 June 30, 1995:
Updated my email address.
Ported to Metrowerks CodeWarrior.
Shortened name LAP gives MacTCP for control panel window so slot number is displayed.
Improved RawIP.h's compatability with Universal Headers.